package cn.schoolwow.ams.test.module.flowLog.flow.initial;

import cn.schoolwow.ams.test.entity.User;
import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class InitialUserTableDataFlow implements BusinessFlow, InitializingBean {
    @Autowired
    private QuickFlow quickFlow;

    @Autowired
    private DAO starterDAO;

    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.putData("username", "ams");
        flowContext.putData("password", "123456");

        String username = flowContext.checkData("username", String.class);
        String password = flowContext.checkData("password", String.class);
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        starterDAO.insertIgnore(user);
    }

    @Override
    public String name() {
        return "初始化用户表数据";
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        quickFlow.executeFlow(this);
    }
}
